﻿using EmoneyWeiXinCommon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace EmoneyWeiXinDAL
{
    public class HuaYuanDanDAL
    {

        /// <summary>
        /// 添加一条抽奖记录
        /// </summary>
        /// <returns></returns>
        public static int AddChouJiangRec(string weixinid, string openid, int result)
        {
            string sql = "proc_AddHuaYuanDAN_ChouJiangRec";
            SqlParameter[] paras =
            {
              new SqlParameter("@weixinId",weixinid),
              new SqlParameter("@openid",openid),
              new SqlParameter("@result",result),
              new SqlParameter("@ChDate",System.DateTime.Now.ToString("yyyyMMdd")),
            };
            return SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.StoredProcedure, sql, paras);
        }

        public static int Tixian(string weixinId, string openid, string orderNum, out decimal money)
        {
            int count = 0;
            string sql = "proc_HuaYuanDAN_Tixian";
            SqlParameter[] paras =
            {
              new SqlParameter("@openid",openid),
              new SqlParameter("@weixinId",weixinId),
              new SqlParameter("@orderNum",orderNum),
              new SqlParameter("@getMoney",System.Data.SqlDbType.Decimal)
            };
            paras[3].Direction = System.Data.ParameterDirection.Output;
            object obj = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.StoredProcedure, sql, paras);
            //int count = SQLHelper.ExecuteNonQuery(tran, System.Data.CommandType.StoredProcedure, sql, paras);
            money = Convert.ToDecimal(paras[3].Value);
            return count;
        }


        
        public static int UpdateRec(string weixinId, string openid, string orderNum,  decimal money,int isok)
        {
            int count = 0;
            string sql = "proc_HuayuandanUpdateRecAddRec";
            SqlParameter[] paras =
            {                 
             
              new SqlParameter("@openid",openid),
              new SqlParameter("@weixinId",weixinId),
              new SqlParameter("@orderNum",orderNum),
              new SqlParameter("@getMoney",money),
              new SqlParameter("@isok",isok),
              
            };
            //paras[3].Direction = System.Data.ParameterDirection.Output;
            object obj = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, System.Data.CommandType.StoredProcedure, sql, paras);
            //int count = SQLHelper.ExecuteNonQuery(tran, System.Data.CommandType.StoredProcedure, sql, paras);

            count = Convert.ToInt32(paras[4].Value);
            return count;

    
        }


    }
}
